#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
bool vis[9][9];
int all,n,grade[9],ans,tot;
void dfs(int start,int dep,int all)
{
	if(all/2*3<tot||all>tot)return;
	if(start==1&&dep!=1&&grade[dep-1])return;
	if(!grade[dep]&&start==n&&dep==n){ans++;return;}
	if(vis[dep][start])
	{
		if(start==n)dfs(1,dep+1,all);
		else dfs(start+1,dep,all);
		return ;
	}
	vis[dep][start]=true;
	vis[start][dep]=true;
	if(grade[dep]-3>=0)
	{
		grade[dep]-=3;
		tot-=3;
		if(start==n)dfs(1,dep+1,all-2);
		else dfs(start+1,dep,all-2);
		tot+=3;
		grade[dep]+=3;
	}
	if(grade[dep]-1>=0&&grade[start]-1>=0)
	{
		grade[dep]-=1;
		grade[start]-=1;
		tot-=2;
		if(start==n)dfs(1,dep+1,all-2);
		else dfs(start+1,dep,all-2);
		tot+=2;
		grade[dep]+=1;
		grade[start]+=1;
	}
	if(grade[start]-3>=0)
	{
		grade[start]-=3;
		tot-=3;
		if(start==n)dfs(1,dep+1,all-2);
		else dfs(start+1,dep,all-2);
		tot+=3;
		grade[start]+=3;
	}
	vis[dep][start]=false;
	vis[start][dep]=false;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&grade[i]),vis[i][i]=true,tot+=grade[i];
	dfs(1,1,n*(n-1));
	printf("%d",ans);
	return 0;
}
